using System;
using Science.Mathematics;
using L=Science.Physics.GeneralPhysics;
using M = Science.Mathematics.Calculus;

namespace Serway.Chapter23
{
	/// <summary>
	/// Example07: The Electric Field Due to a Charged Rod
	/// A rod of length l has a uniform positive charge per
	/// unit length \lambda and a total charge Q. Calculate
	/// the electric field at a point P that is located along
	/// the long axis of the rod and a distance a from one end.
	/// E = k_e Q / (a(l+a))	
	/// </summary>
	public class Example07
	{
		public Example07()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		double ke = L.Constant.CoulombConstant;
		double Q = 10.0;
		double l = 2.0;
		double rho;
		double a = 3.0;
		public void Compute()
		{
			rho = Q/l;
			Function.DoubleToDouble E
				= new Function.DoubleToDouble(func);
			M.Integration1D proj = new M.Integration1D(E);
            proj.From = a;
			proj.To = l + a;
			proj.Compute();

			result+=Convert.ToString(proj.Result)+"\r\n";  
			result+=Convert.ToString(ke*Q/a/(l+a))+"\r\n";  
		}
		private double func(double x)
		{
			return ke*rho/x/x;
		}
	}
}
